from django.db import models
# Create your models here.
# 商品类别表
class GoodCategory(models.Model):
    cate_name = models.CharField('商品类别', max_length=20)

    class Meta:
        db_table = 'goods_goodcategory_tb'
        verbose_name = '商品种类'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.cate_name

# 商品信息表
class Good(models.Model):
    sku_name = models.CharField('商品名',max_length=100)
    price = models.DecimalField('价格',max_digits=13,decimal_places=2)
    selling_price = models.DecimalField('当前售价',max_digits=13,decimal_places=2)
    img = models.CharField('图片地址',max_length=200)
    title = models.CharField('标题',max_length=30)
    instruction = models.TextField('商品介绍',max_length=2000)
    count = models.IntegerField(verbose_name="商品数量",default=0)
    stock = models.IntegerField('商品库存',default=0)
    cate = models.ForeignKey(GoodCategory,on_delete=models.CASCADE)
    online = models.BooleanField('是否在售',default=True)

    class Meta:
        db_table = 'goods_good_tb'
        verbose_name = '商品信息表'
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.sku_name

# 商品图片表
class GoodImg(models.Model):
    img = models.CharField('图片地址',max_length=200)
    title = models.CharField('图片描述',max_length=20,null=True)
    good = models.ForeignKey(Good,on_delete=models.CASCADE)

    class Meta:
        db_table = 'goods_goodimg_tb'
        verbose_name = '商品图片表'
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.good.sku_name



class Caeousel(models.Model):
    imgPath=models.CharField("轮播图地址",max_length=100)
    verbose= models.CharField("描述信息", max_length=100)

    class Meta:
        db_table ="goods_carousel_tb"
        verbose_name_plural ="轮播图"

    def __set__(self):
        return "轮播图%d"%self.id


